<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>
    <link href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
    <script>
    
    hljs.initHighlightingOnLoad();  <!-- 初始化高亮插件,但只能初始化一开始存在的元素  -->
    
    <!--  当数据变化后,动态高亮指定元素 -->
    function myHighlighting(targetId){
        $("#"+targetId).load("http://www.xxx.com/javaCode.java",{},function(response){//response即为www.xxx.com返回的java代码
            var code = hljs.highlightAuto(response).value;
            $("#"+targetId).html(code);
        });
    }
    </script> 
<title>高亮java代码</title>
</head>
<body>
    <!-- 这个class要指定java -->
    <pre><code class="java" id="PersonCode" onclick="myHighlighting('PersonCode')">
    	public static final float player_block_reach = 2.75F;//玩家手长
	public static final float player_attack_reach = 1.5F;//攻击距离
    </code></pre>
</body>
</html>